package com.jboom.templates.statemachine.java.state;

/**
 * @author zhangwen
 * @date 2023/5/25 20:58
 */
public class Context extends State {

    public static final State OPEN_STATE = new OpenState();

    public static final State CLOSE_STATE = new CloseState();

    public static final State RUNNING_STATE = new RunningState();

    public static final State STOP_STATE = new StopState();

    private State curState;

    public Context(State curState) {
        this.curState = curState;
    }

    {
        OPEN_STATE.context = this;
        CLOSE_STATE.context = this;
        RUNNING_STATE.context = this;
        STOP_STATE.context = this;
    }

    @Override
    protected void open() {
        curState.open();
    }

    @Override
    protected void close() {
        curState.close();
    }

    @Override
    protected void running() {
        curState.running();
    }

    @Override
    protected void stop() {
        curState.stop();
    }

    public void setCurState(State curState) {
        this.curState = curState;
    }
}
